package com.example.drive.net.request

import okhttp3.Request

/**
 * get请求
 */
class GetRequest constructor(
    private var url: String,
    tag: Any = Any(),
    private val params: Map<String, String> = mapOf()
) : OkHttpRequest(url, tag) {
    override fun createRequest(): Request {
        val requestUrl = if (params.isEmpty()) {
            url
        } else {
            // 拼接参数,记得去掉最后一个&
            val sb = StringBuilder(url).append("?")
            params.forEach {
                sb.append(it.key).append("=").append(it.value).append("&")
            }
            sb.substring(0, sb.length - 1)
        }
        return builder.url(requestUrl).get().build()
    }
}